/******************************************************************************
//             INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in accordance with the terms of that agreement.
//        Copyright (c) 2000-2001 Intel Corporation. All Rights Reserved.
//
//  Description:
//      Intel(R) JPEG library for X platform 
//
********************************************************************************/
#include "_ijx.h"

///////////////////////////////////////
//These functions are supported in this version
///////////////////////////////////////
#ifdef _MOTION_DIFF

extern const Ipp8u _nIZigZagIndex[64];

/******************************************************************************
// Name:            ijMotionDiffDecoder_MCU_First_16s_C1
// Description:     Huffman decoder for 1 component image.
// Input Arguments:
// Output Arguments:
// Returns:          
//        [Success] IJX_RTCODE_OK
//        [Failure] IJX_RTCODE_BAGARG
//                  IJX_RTCODE_ERROR
//                     
//                  
******************************************************************************/
IJXRESULT ijMotionDiffDecoder_MCU_First_16s_C1 (IJBUFFER         *pIJXBuffer,
                                                IJBITTREAMSTATE  *pStream,
                                                IJDECODESTATE    *pDecodeState)
{
    IJXRESULT rtCode;

    Ipp16s *pCoefBuf         = pIJXBuffer->paCoeffBufCur[0];
    Ipp32s *pDCTDequantTable = (Ipp32s *)(pDecodeState->paIdxDCTDequantTable[0]);

    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                               &(pStream->nUsedBufBitsLen),
                                               pCoefBuf,
                                               &(pDecodeState->dcPred[0]),
                                               &(pDecodeState->nMarker),
                                               &(pStream->nPrefetchedBits),
                                               &(pStream->nNumValidPrefetchedBits),
                                               pDecodeState->paIdxDCHuffTable[0],
                                               pDecodeState->paIdxACHuffTable[0]);

#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif
    
    ippiDCTQuantInv_JPEG_16s_I(pCoefBuf, pDCTDequantTable);

    //pIJXBuffer->paCoeffBufCur[0]+=64;
    
    return IJX_RTCODE_OK;
}

/******************************************************************************
// Name:            ijMotionDiffDecoder_MCU_Refine_16s_C1
// Description:     Huffman decoder for 1 component image.
// Input Arguments:
// Output Arguments:
//                          
// Returns:          
//        [Success] IJX_RTCODE_OK
//        [Failure] IJX_RTCODE_BAGARG
//                  IJX_RTCODE_ERROR
//                     
//                  
******************************************************************************/
IJXRESULT ijMotionDiffDecoder_MCU_Refine_16s_C1 (IJBUFFER         *pIJXBuffer,
                                                IJBITTREAMSTATE  *pStream,
                                                IJDECODESTATE    *pDecodeState)
{
    IJXRESULT rtCode;

    Ipp16s *pMCUBuf          = pIJXBuffer->paMCUBufCur[0];
    Ipp16s *pCoefBuf         = pIJXBuffer->paCoeffBufCur[0];
    Ipp32s *pDCTDequantTable = (Ipp32s *)(pDecodeState->paIdxDCTDequantTable[0]);

    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                               &(pStream->nUsedBufBitsLen),
                                               pMCUBuf,
                                               &(pDecodeState->dcPred[0]),
                                               &(pDecodeState->nMarker),
                                               &(pStream->nPrefetchedBits),
                                               &(pStream->nNumValidPrefetchedBits),
                                               pDecodeState->paIdxDCHuffTable[0],
                                               pDecodeState->paIdxACHuffTable[0]);

#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif
    
    ippiDCTQuantInv_JPEG_16s_I(pMCUBuf, pDCTDequantTable);
    ippiAddBlock_8x8_16s_I(pMCUBuf, pCoefBuf, 1);
    //pIJXBuffer->paCoeffBufCur[0]+=64;
    
    return IJX_RTCODE_OK;
}

/******************************************************************************
// Name:            ijMotionDiffDecoder_MCU444_First_16s_C3
// Description:     Huffman decoder for 444 image.
// Input Arguments:
// Output Arguments:
//                          
// Returns:          
//        [Success] IJX_RTCODE_OK
//        [Failure] IJX_RTCODE_BAGARG
//                  IJX_RTCODE_ERROR
//                     
//                  
******************************************************************************/
IJXRESULT ijMotionDiffDecoder_MCU444_First_16s_C3 (IJBUFFER         *pIJXBuffer,
                                                   IJBITTREAMSTATE  *pStream,
                                                   IJDECODESTATE    *pDecodeState)
{
    IJXRESULT rtCode;
    Ipp16s **ppCoefBuf         = (Ipp16s **)(pIJXBuffer->paCoeffBufCur);
    Ipp32s **ppDCTDequantTable = (Ipp32s **)(pDecodeState->paIdxDCTDequantTable);

    // Channel 1
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppCoefBuf[0],
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppCoefBuf[0], ppDCTDequantTable[0]);
    //pIJXBuffer->paCoeffBufCur[0]+=64;

    // Channel 2
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppCoefBuf[1],
                                         &(pDecodeState->dcPred[1]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[1],
                                         pDecodeState->paIdxACHuffTable[1]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppCoefBuf[1], ppDCTDequantTable[1]);
    //pIJXBuffer->paCoeffBufCur[1]+=64;

    // Channel 3
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppCoefBuf[2],
                                         &(pDecodeState->dcPred[2]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[2],
                                         pDecodeState->paIdxACHuffTable[2]);

#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppCoefBuf[2], ppDCTDequantTable[2]);
    //pIJXBuffer->paCoeffBufCur[2]+=64;

    return IJX_RTCODE_OK;
}

/******************************************************************************
// Name:            ijMotionDiffDecoder_MCU444_Refine_16s_C3
// Description:     Huffman decoder for 444 image.
// Input Arguments:
// Output Arguments:
//                          
// Returns:          
//        [Success] IJX_RTCODE_OK
//        [Failure] IJX_RTCODE_BAGARG
//                  IJX_RTCODE_ERROR
//                     
//                  
******************************************************************************/
IJXRESULT ijMotionDiffDecoder_MCU444_Refine_16s_C3(IJBUFFER         *pIJXBuffer,
                                                   IJBITTREAMSTATE  *pStream,
                                                   IJDECODESTATE    *pDecodeState)
{
    IJXRESULT rtCode;
    Ipp16s **ppMCUBuf          = (Ipp16s **)(pIJXBuffer->paMCUBufCur);
    Ipp16s **ppCoefBuf         = (Ipp16s **)(pIJXBuffer->paCoeffBufCur);
    Ipp32s **ppDCTDequantTable = (Ipp32s **)(pDecodeState->paIdxDCTDequantTable);

    // Channel 1
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppMCUBuf[0],
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppMCUBuf[0], ppDCTDequantTable[0]);
    ippiAddBlock_8x8_16s_I(ppMCUBuf[0], ppCoefBuf[0], 1);
    //pIJXBuffer->paCoeffBufCur[0]+=64;

    // Channel 2
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppMCUBuf[1],
                                         &(pDecodeState->dcPred[1]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[1],
                                         pDecodeState->paIdxACHuffTable[1]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppMCUBuf[1], ppDCTDequantTable[1]);
    ippiAddBlock_8x8_16s_I(ppMCUBuf[1], ppCoefBuf[1], 1);
    //pIJXBuffer->paCoeffBufCur[1]+=64;

    // Channel 3
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppMCUBuf[2],
                                         &(pDecodeState->dcPred[2]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[2],
                                         pDecodeState->paIdxACHuffTable[2]);

#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppMCUBuf[2], ppDCTDequantTable[2]);
    ippiAddBlock_8x8_16s_I(ppMCUBuf[2], ppCoefBuf[2], 1);
    //pIJXBuffer->paCoeffBufCur[2]+=64;

    return IJX_RTCODE_OK;
}

/******************************************************************************
// Name:            ijMotionDiffDecoder_MCU422_First_16s_C3
// Description:     Huffman decoder for 422 image.
// Input Arguments:
// Output Arguments:
//                          
// Returns:          
//        [Success] IJX_RTCODE_OK
//        [Failure] IJX_RTCODE_BAGARG
//                  IJX_RTCODE_ERROR
//                     
//                  
******************************************************************************/
IJXRESULT ijMotionDiffDecoder_MCU422_First_16s_C3 (IJBUFFER         *pIJXBuffer,
                                                   IJBITTREAMSTATE  *pStream,
                                                   IJDECODESTATE    *pDecodeState)
{
    IJXRESULT rtCode;
    //Ipp16s **ppMCUBuf          = (Ipp16s **)(pIJXBuffer->paMCUBufCur);
    Ipp16s **ppCoefBuf         = (Ipp16s **)(pIJXBuffer->paCoeffBufCur);
    Ipp32s **ppDCTDequantTable = (Ipp32s **)(pDecodeState->paIdxDCTDequantTable);

    //Channel 1
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppCoefBuf[0],
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         &(ppCoefBuf[0][64]),
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppCoefBuf[0], ppDCTDequantTable[0]);
    ippiDCTQuantInv_JPEG_16s_I(&(ppCoefBuf[0][64]), ppDCTDequantTable[0]);

    //pIJXBuffer->paCoeffBufCur[0]+=128;

    //Channel 2
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppCoefBuf[1],
                                         &(pDecodeState->dcPred[1]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[1],
                                         pDecodeState->paIdxACHuffTable[1]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif
    ippiDCTQuantInv_JPEG_16s_I(ppCoefBuf[1], ppDCTDequantTable[1]);
    //pIJXBuffer->paCoeffBufCur[1]+=64;

    //Channel 3
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppCoefBuf[2],
                                         &(pDecodeState->dcPred[2]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[2],
                                         pDecodeState->paIdxACHuffTable[2]);

#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif
    ippiDCTQuantInv_JPEG_16s_I(ppCoefBuf[2], ppDCTDequantTable[2]);
    //pIJXBuffer->paCoeffBufCur[2]+=64;

    return IJX_RTCODE_OK;
}

/******************************************************************************
// Name:            ijMotionDiffDecoder_MCU422_Refine_16s_C3
// Description:     Huffman decoder for 422 image.
// Input Arguments:
// Output Arguments:
//                          
// Returns:          
//        [Success] IJX_RTCODE_OK
//        [Failure] IJX_RTCODE_BAGARG
//                  IJX_RTCODE_ERROR
//                     
//                  
******************************************************************************/
IJXRESULT ijMotionDiffDecoder_MCU422_Refine_16s_C3 (IJBUFFER         *pIJXBuffer,
                                                   IJBITTREAMSTATE  *pStream,
                                                   IJDECODESTATE    *pDecodeState)
{
    IJXRESULT rtCode;
    Ipp16s **ppMCUBuf          = (Ipp16s **)(pIJXBuffer->paMCUBufCur);
    Ipp16s **ppCoefBuf         = (Ipp16s **)(pIJXBuffer->paCoeffBufCur);
    Ipp32s **ppDCTDequantTable = (Ipp32s **)(pDecodeState->paIdxDCTDequantTable);

    //Channel 1
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppMCUBuf[0],
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         &(ppMCUBuf[0][64]),
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppMCUBuf[0], ppDCTDequantTable[0]);
    ippiDCTQuantInv_JPEG_16s_I(&(ppMCUBuf[0][64]), ppDCTDequantTable[0]);
    ippiAddBlock_8x8_16s_I(ppMCUBuf[0], ppCoefBuf[0], 2);

    //pIJXBuffer->paCoeffBufCur[0]+=128;

    //Channel 2
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppMCUBuf[1],
                                         &(pDecodeState->dcPred[1]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[1],
                                         pDecodeState->paIdxACHuffTable[1]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppMCUBuf[1], ppDCTDequantTable[1]);
    ippiAddBlock_8x8_16s_I(ppMCUBuf[1], ppCoefBuf[1], 1);
    //pIJXBuffer->paCoeffBufCur[1]+=64;

    //Channel 3
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppMCUBuf[2],
                                         &(pDecodeState->dcPred[2]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[2],
                                         pDecodeState->paIdxACHuffTable[2]);

#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppMCUBuf[2], ppDCTDequantTable[2]);
    ippiAddBlock_8x8_16s_I(ppMCUBuf[2], ppCoefBuf[2], 1);
    //pIJXBuffer->paCoeffBufCur[2]+=64;

    return IJX_RTCODE_OK;
}

/******************************************************************************
// Name:            ijMotionDiffDecoder_MCU411_First_16s_C3
// Description:     Huffman decoder for 422 image.
// Input Arguments:
// Output Arguments:
//                          
// Returns:          
//        [Success] IJX_RTCODE_OK
//        [Failure] IJX_RTCODE_BAGARG
//                  IJX_RTCODE_ERROR
//                     
//                  
******************************************************************************/
IJXRESULT ijMotionDiffDecoder_MCU411_First_16s_C3 (IJBUFFER         *pIJXBuffer,
                                                   IJBITTREAMSTATE  *pStream,
                                                   IJDECODESTATE    *pDecodeState)
{
    IJXRESULT rtCode;
    //Ipp16s **ppMCUBuf          = (Ipp16s **)(pIJXBuffer->paMCUBufCur);
    Ipp16s **ppCoefBuf         = (Ipp16s **)(pIJXBuffer->paCoeffBufCur);
    Ipp32s **ppDCTDequantTable = (Ipp32s **)(pDecodeState->paIdxDCTDequantTable);

    //Channel 1
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppCoefBuf[0],
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         &(ppCoefBuf[0][64]),
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         &(ppCoefBuf[0][128]),
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         &(ppCoefBuf[0][192]),
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppCoefBuf[0], ppDCTDequantTable[0]);
    ippiDCTQuantInv_JPEG_16s_I(&(ppCoefBuf[0][64]),  ppDCTDequantTable[0]);
    ippiDCTQuantInv_JPEG_16s_I(&(ppCoefBuf[0][128]), ppDCTDequantTable[0]);
    ippiDCTQuantInv_JPEG_16s_I(&(ppCoefBuf[0][192]), ppDCTDequantTable[0]);

    //pIJXBuffer->paCoeffBufCur[0]+=256;

    // Channel 2
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppCoefBuf[1],
                                         &(pDecodeState->dcPred[1]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[1],
                                         pDecodeState->paIdxACHuffTable[1]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppCoefBuf[1], ppDCTDequantTable[1]);
    //pIJXBuffer->paCoeffBufCur[1]+=64;

    // Channel 3
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppCoefBuf[2],
                                         &(pDecodeState->dcPred[2]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[2],
                                         pDecodeState->paIdxACHuffTable[2]);

#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppCoefBuf[2], ppDCTDequantTable[2]);
    //pIJXBuffer->paCoeffBufCur[2]+=64;

    return IJX_RTCODE_OK;
}

/******************************************************************************
// Name:            ijMotionDiffDecoder_MCU411_Refine_16s_C3
// Description:     Huffman decoder for 422 image.
// Input Arguments:
// Output Arguments:
//                          
// Returns:          
//        [Success] IJX_RTCODE_OK
//        [Failure] IJX_RTCODE_BAGARG
//                  IJX_RTCODE_ERROR
//                     
//                  
******************************************************************************/
IJXRESULT ijMotionDiffDecoder_MCU411_Refine_16s_C3 (IJBUFFER         *pIJXBuffer,
                                                   IJBITTREAMSTATE  *pStream,
                                                   IJDECODESTATE    *pDecodeState)
{
    IJXRESULT rtCode;
    Ipp16s **ppMCUBuf          = (Ipp16s **)(pIJXBuffer->paMCUBufCur);
    Ipp16s **ppCoefBuf         = (Ipp16s **)(pIJXBuffer->paCoeffBufCur);
    Ipp32s **ppDCTDequantTable = (Ipp32s **)(pDecodeState->paIdxDCTDequantTable);

    //Channel 1
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppMCUBuf[0],
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         &(ppMCUBuf[0][64]),
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         &(ppMCUBuf[0][128]),
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         &(ppMCUBuf[0][192]),
                                         &(pDecodeState->dcPred[0]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[0],
                                         pDecodeState->paIdxACHuffTable[0]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppMCUBuf[0], ppDCTDequantTable[0]);
    ippiDCTQuantInv_JPEG_16s_I(&(ppMCUBuf[0][64]), ppDCTDequantTable[0]);
    ippiDCTQuantInv_JPEG_16s_I(&(ppMCUBuf[0][128]), ppDCTDequantTable[0]);
    ippiDCTQuantInv_JPEG_16s_I(&(ppMCUBuf[0][192]), ppDCTDequantTable[0]);
    ippiAddBlock_8x8_16s_I(ppMCUBuf[0], ppCoefBuf[0], 4);

    //pIJXBuffer->paCoeffBufCur[0]+=256;

    // Channel 2
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppMCUBuf[1],
                                         &(pDecodeState->dcPred[1]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[1],
                                         pDecodeState->paIdxACHuffTable[1]);
#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppMCUBuf[1], ppDCTDequantTable[1]);
    ippiAddBlock_8x8_16s_I(ppMCUBuf[1], ppCoefBuf[1], 1);
    //pIJXBuffer->paCoeffBufCur[1]+=64;

    // Channel 3
    rtCode=ippiDecodeHuffman_Direct_JPEG_1u16s (pStream->pBitStream,  
                                         &(pStream->nUsedBufBitsLen),
                                         ppMCUBuf[2],
                                         &(pDecodeState->dcPred[2]),
                                         &(pDecodeState->nMarker),
                                         &(pStream->nPrefetchedBits),
                                         &(pStream->nNumValidPrefetchedBits),
                                         pDecodeState->paIdxDCHuffTable[2],
                                         pDecodeState->paIdxACHuffTable[2]);

#ifdef _IJX_HUFFMANBADCHK
    if (!IJX_SUCCEEDED(rtCode)) {
        return IJX_RTCODE_ERROR;
    }
#endif

    ippiDCTQuantInv_JPEG_16s_I(ppMCUBuf[2], ppDCTDequantTable[2]);
    ippiAddBlock_8x8_16s_I(ppMCUBuf[2], ppCoefBuf[2], 1);
 //   pIJXBuffer->paCoeffBufCur[2]+=64;

    return IJX_RTCODE_OK;
}

#endif
///////////////////////////////////////

/* EOF */
